package com.redis.demo.init;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import redis.clients.jedis.Jedis;

@Configuration
public class RedisConfig {

	public static final String DB_HOST_PROPERTY_NAME = "host";
	public static final String DB_PORT_PROPERTY_NAME = "port";

	@Resource
	private Environment envir;

	@Bean
	public Jedis jedis() {
		Jedis jedis = new Jedis(
				envir.getRequiredProperty(RedisConfig.DB_HOST_PROPERTY_NAME),
				envir.getProperty(RedisConfig.DB_PORT_PROPERTY_NAME,
						Integer.class));

		return jedis;
	}
}
